<?php

namespace App\Http\Controllers\Backend;

use App\Http\Requests\UpdateUserRequest;
use App\Models\User;

class UsersController extends Controller
{
    /**
     * 用户编辑页面
     *
     * @param  integer $id
     * @return \Illuminate\View\View
     */
    public function edit($id)
    {
        $user = User::findOrFail($id);

        return view('backend.users.edit', compact('user'));
    }

    /**
     * 用户编辑
     *
     * @param  integer $id
     * @param  \App\Http\Requests\UpdateUserRequest $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function update($id, UpdateUserRequest $request)
    {
        $user = User::findOrFail($id);

        $user->update([
            'avater'         => $request->get('avater') ?? '',
            'github_account' => $request->get('github_account') ?? '',
        ]);

        return redirect()->route('users.edit', 'me');
    }
}
